using UnityEngine;

public class VehicleUpgradesPreviewer : MonoBehaviour
{
	[SerializeField]
	[Header("Все меши транспорта без апгрейдов")]
	private Renderer[] vehicleRenderers;

	[SerializeField]
	[Header("Стандартный материал транспорта")]
	private Material defaultMaterial;

	[SerializeField]
	[Header("Полупрозрачный материал транспорта")]
	private Material previewMaterial;

	[SerializeField]
	[Header("Меши апгрейдов. Списки должны быть упорядочены.")]
	[Header("Корпус, кузов и т.п.")]
	private GameObject[] bodyUpgrades;

	[Header("Мотор, движок и т.п.")]
	[SerializeField]
	private GameObject[] engineUpgrades;

	[Header("Воздухозаборники, турбина и т.п. (в танках сюда пушку)")]
	[SerializeField]
	private GameObject[] intakeUpgrades;

	[SerializeField]
	[Header("Колеса, трансмиссия и т.п.")]
	private GameObject[] wheelsUpgrades;

	public void ShowDefault()
	{
		Renderer[] array = vehicleRenderers;
		foreach (Renderer renderer in array)
		{
			renderer.material = defaultMaterial;
		}
		HideAllUpgrades();
	}

	private void HideAllUpgrades()
	{
		GameObject[] array = bodyUpgrades;
		foreach (GameObject gameObject in array)
		{
			gameObject.SetActive(false);
		}
		GameObject[] array2 = engineUpgrades;
		foreach (GameObject gameObject2 in array2)
		{
			gameObject2.SetActive(false);
		}
		GameObject[] array3 = intakeUpgrades;
		foreach (GameObject gameObject3 in array3)
		{
			gameObject3.SetActive(false);
		}
		GameObject[] array4 = wheelsUpgrades;
		foreach (GameObject gameObject4 in array4)
		{
			gameObject4.SetActive(false);
		}
	}

	private void ShowTransparent()
	{
		Renderer[] array = vehicleRenderers;
		foreach (Renderer renderer in array)
		{
			renderer.material = previewMaterial;
		}
		HideAllUpgrades();
	}

	private void ShowBodyUp(int upNumber)
	{
		ShowTransparent();
		if (upNumber >= 0 && upNumber < bodyUpgrades.Length)
		{
			bodyUpgrades[upNumber].SetActive(true);
		}
	}

	private void ShowIntakeUp(int upNumber)
	{
		ShowTransparent();
		if (upNumber >= 0 && upNumber < intakeUpgrades.Length)
		{
			intakeUpgrades[upNumber].SetActive(true);
		}
	}

	private void ShowEngineUp(int upNumber)
	{
		ShowTransparent();
		if (upNumber >= 0 && upNumber < engineUpgrades.Length)
		{
			engineUpgrades[upNumber].SetActive(true);
		}
	}

	private void ShowWheelsUp(int upNumber)
	{
		ShowTransparent();
		if (upNumber >= 0 && upNumber < wheelsUpgrades.Length)
		{
			wheelsUpgrades[upNumber].SetActive(true);
		}
	}

	public void ShowUpgradeOfType(UpgradeType type, int upgradeNumber)
	{
		switch (type)
		{
		case UpgradeType.Body:
			ShowBodyUp(upgradeNumber);
			break;
		case UpgradeType.Engine:
			ShowEngineUp(upgradeNumber);
			break;
		case UpgradeType.Intake:
			ShowIntakeUp(upgradeNumber);
			break;
		case UpgradeType.Wheels:
			ShowWheelsUp(upgradeNumber);
			break;
		}
	}

	public void ShowSkin(Texture texture)
	{
		if (!(texture == null))
		{
			ShowDefault();
			Renderer[] array = vehicleRenderers;
			foreach (Renderer renderer in array)
			{
				renderer.material.mainTexture = texture;
			}
		}
	}
}
